<script setup>
import { ref } from 'vue'
import  useBuyerInfoStore from '@/stores/buyerInfo.js'
const buyerInfoStore = useBuyerInfoStore();

const buyerInfo = ref({...buyerInfoStore.info})

const pwdInfo=ref({
      oldBuyer_pwd: '',
      newBuyer_pwd:'',
      reBuyer_pwd:''
    }
)


//修改密码
import {buyerInfoUpdatePwdService} from '@/api/buyer.js'
import {ElMessage} from 'element-plus'
const updateBuyerPwd = async ()=>{
  //调用接口
  let result = await buyerInfoUpdatePwdService(pwdInfo.value);
  ElMessage.success(result.msg? result.msg : '修改成功');
  //修改pinia中的密码
  buyerInfoStore.setInfo({ ...buyerInfoStore.info, password: pwdInfo.value.newBuyer_pwd });
}
console.log(buyerInfo.value);
</script>


<template>
  <el-card class="page-buyerContainer">
    <template #header>
      <div class="header">
        <span>重置密码</span>
      </div>
    </template>
    <el-row>
      <el-col :span="12">
        <el-form :model="buyerInfo" :rules="rules" label-width="100px" size="large">
          <el-form-item label="登录名称">
            <el-input v-model="buyerInfo.username" disabled></el-input>
          </el-form-item>


          <el-form-item label="旧密码">
            <el-input v-model="pwdInfo.oldBuyer_pwd" type="password"></el-input>
          </el-form-item>

          <el-form-item label="新密码">
            <el-input v-model="pwdInfo.newBuyer_pwd" type="password"></el-input>
          </el-form-item>

          <el-form-item label="再次输入">
            <el-input v-model="pwdInfo.reBuyer_pwd" type="password"></el-input>
          </el-form-item>


          <el-form-item>
            <el-button type="primary" @click="updateBuyerPwd">提交修改</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </el-card>
</template>